/**
 * Copyright (C) 2002-2006 WUZEWEN. All rights reserved.
 * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package wzw.manager;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.HashMap;

/**
 * <p>剪贴板管理类</p>
 * @author	WUZEWEN on 2006-4-29
 * @version	1.0
 * @see		Object#equals(java.lang.Object)
 * @see		Object#hashCode()
 * @see		HashMap
 * @since	JDK5
 */

public class ClipboardManager {    
	
	/**     
	 * 设置剪贴板的内容     
	 * @param content 要粘贴到剪切板的文字
	 *
	 */    
	public static void setClipBoardContents(String content) {        
		try {            //复制到剪贴板            
			StringSelection stringSelection = new StringSelection(content);
			Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
			clipboard.setContents(stringSelection, null);
		}        catch (Exception e) {            
			e.printStackTrace();
		}    
	} 
	
	/**
	 * 获得剪贴板的内容     
	 * @return
	 *
	 */    
	public static String getClipBoardContents() {        
		String text = "";
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		Transferable contents = clipboard.getContents(null);
		boolean hasTransferableText = (contents != null) &&            contents.isDataFlavorSupported(DataFlavor.stringFlavor);
		if (hasTransferableText) {            
			try {                
				text = (String) contents.getTransferData(DataFlavor.stringFlavor);
				return text;
			}            catch (UnsupportedFlavorException ex) {  
				ex.printStackTrace();
			}            catch (IOException ex) {    
				ex.printStackTrace();
			}        }  
		return null;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}
}